#ifndef COMMON_H
#define COMMON_H

//general
//#include <mutex>
#include <iostream>
#include <stdio.h>
#include <unistd.h>
#include <signal.h>
#include <string>
#include <sstream>
//#include <pthread.h>
#include <thread>
#include <fstream>  
#include <vector>
#include <map>
#include <cmath>
#include <assert.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <time.h>
//ros
#include <sensor_msgs/LaserScan.h>
#include <tf/tf.h>
#include "ros/ros.h"
#include "logging.h"
#include "std_msgs/String.h"
#include <geometry_msgs/Twist.h>
#include <nav_msgs/Odometry.h>
#include <sensor_msgs/LaserScan.h>

//curl
#include <curl/curl.h>
#include <curl/easy.h>

//socket
#include<netinet/in.h>    
#include<sys/socket.h>    
#include<unistd.h>      
#include<event.h>    
#include<event2/listener.h>    
#include<event2/bufferevent.h>    
#include<event2/thread.h>  

#define PI 3.141593
#define GRAY	127

#define	HITS	1
#define	MISS	0

#define MAP_DEFAULT_VALUE	127
#define OBSTACLE_VALUE		186	//127+3*9
#define FREE_VALUE		73	//127-3*7
//#define MAP_WALL		1	//1
//#define MAP_FLOOR		0	//0

#define SONAR_NUM		12

#define MANUAL_MODE		0
#define AUTO_MODE		1

#define SHARE_KEY		1234
#define SIGNAL_KEY		12345
#define SHM_BUF_SIZE		32

#define	GET_SUB_GOAL		1
#define	GET_FINAL_GOAL		2
#define GO_FOR_GOAL		0

#define REFLECTOR_INTENSITIES	225
#define REFLECTOR_RADIUS 	0.03

#define MANUAL_OBSTACLE		250

#define PATROL			0
#define SENTRY			1

#define LASERUPTURNED		true

//#define CAMERASCAN  
using namespace std;

class CommonFunc
{
    public:
        std::vector<std::string> split(std::string str,std::string pattern);        
		geometry_msgs::Vector3 qurt2euler(const geometry_msgs::Quaternion msg);	
        void rolateWithAxis(const float theta,const int orginPos[2],int goalPos[2]);
        void rolateByAxis(const float theta,const int orginPos[2],int goalPos[2]);
        float angle2_pi_pi(float angle);
        float angle2_2pi(float angle);
        void bresenham(int x1,int y1,int x2,int y2,vector<int> *grid_free_x,vector<int> *grid_free_y);

        template<typename T>
        int sign(const T data){
            if(data>0)
                return 1;
            else
                return -1;
        }
};
#endif
